package com.example.factory.factory;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@Component

@Slf4j
public class ControlCenter {
    @Autowired
    final  Map<String, StrategyInterface> hashMap = new ConcurrentHashMap<>();

    public StrategyInterface getStrategy(StrategyType strategyType) {
        StrategyInterface strategy = hashMap.get(strategyType.name);
        if (strategy == null) {
            log.error("strategy is empty , Please check the realize of strategy or enum ! name := {}", strategyType.name);
            return hashMap.get(StrategyType.BAOMA);
        }
        return strategy;
    }
}
